from PIL import Image
import numpy as np

img = Image.open('1c.jpg', 'r')  # 打开图片，保存为Image对象
width, height = img.size  # 获取图片的大小

# for i in range(500,520):
# img.putpixel((500, i), (255, 0, 255))  # 将new_img的(123, 123)处像素颜色改为白色
# putpixel((width, height), (r, g, b))
for w in range(width):
    for h in range(height):
        # 获取new_img的(123, 123)处像素的值 getpixel((width, height))
        r, g, b = img.getpixel((w, h))
        # if (r,g,b) == (152 ,142 ,133):
        # print(w,h)
        if r > 130 and g > 100 and b > 100:
            img.putpixel(
                (w, h), (255, 255, 255))

# img.show()
# img = img.convert('L') # 将图片转为灰度图片

# img.show() # 显示图片
img.save('demo_L.jpg')  # 保存图片
# data = img.getdata() # 获取图像内容
# img_mat = np.matrix(data) # 将Image对象转为矩阵
# new_img = Image.fromarray(img_mat) # 将矩阵转为Image对象，需要保证矩阵元素类型为uint8，否则会error
# # new_img.show()
some_variable = {
    'long': 'Long code lines should be wrapped within 79 characters.',
    'other': [
        22,
        100,
        200,
        300,
        9876543210,
        'This is a long string that goes on'],
    'more': {
        'inner': 'This whole logical line should be wrapped.',
        's': [
            1,
            20,
            300,
            40000,
            500000000,
            60000000000000000]}}
